package com.mfhcd.facepay.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;

import com.mfhcd.facepay.R;
import com.mfhcd.facepay.databinding.LayoutNormalTagItemBinding;
import com.mfhcd.facepay.model.IndexPageModel;
import com.mfhcd.facepay.utils.LogUtil;
import com.mfhcd.facepay.viewholder.ViewHolder;

import java.util.List;

/**
 * @Author：张洪顺
 * @E-Mail: zhanghs@mfhcd.com
 * @Date：2019-09-17 15:07
 * @版权所有 © 现代金融控股（成都）有限公司
 * @描述：首页标签适配器
 */
public class IndexPageTagAdapter extends BaseAdapter<IndexPageModel, LayoutNormalTagItemBinding> {
    private OnMenuItemClickListener onMenuItemClickListener;

    public OnMenuItemClickListener getOnMenuItemClickListener() {
        return onMenuItemClickListener;
    }

    public void setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener) {
        this.onMenuItemClickListener = onMenuItemClickListener;
    }

    public IndexPageTagAdapter(@Nullable List<IndexPageModel> data) {
        super(R.layout.layout_normal_tag_item, data);
    }

    @Override
    protected void convert(@NonNull ViewHolder<LayoutNormalTagItemBinding> helper, IndexPageModel item) {
        helper.binding.setItemModel(item);
        IndexPageTagFunctionAdapter functionAdapter = new IndexPageTagFunctionAdapter(item.getSubList());
        helper.binding.rvList.setLayoutManager(new GridLayoutManager(mContext, 3));
        helper.binding.rvList.setAdapter(functionAdapter);
        functionAdapter.setOnItemClickListener((adapter, view, position) -> {
            IndexPageModel itemModel = item.getSubList().get(position);
            LogUtil.d(itemModel.getCode() + "--" + itemModel.getName());
            if (onMenuItemClickListener != null) {
                getOnMenuItemClickListener().OnMenuItemClick(itemModel.getCode(), itemModel.getName());
            }
        });
        helper.binding.executePendingBindings();
    }

    public interface OnMenuItemClickListener {
        /**
         * item操作回调
         */
        void OnMenuItemClick(String code, String name);
    }
}
